package com.woniuxy.controller;

import com.woniuxy.entity.SessionMessages;
import com.woniuxy.service.AIService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

/**
 * @Author: 马宇航
 * @Todo: 蜗牛在线的咨询客服的
 * @DateTime: 25/08/27/星期三 17:09
 * @Component: 成都蜗牛学苑
 **/
@RestController
@RequestMapping("/ai")
@CrossOrigin
public class AIVectorController {
//    private static final Logger logger = LoggerFactory.getLogger(BailianAgentStreamController.class);

    @Autowired
    AIService aiService;
    //text/event-stream 就是SSE模式，单向推送 长数据拆分成短数据响应
    @PostMapping(value="/stream", produces="text/event-stream")
    public Flux<String> stream(@RequestBody SessionMessages message) {
        //非流式方案
//        Prompt prompt = new Prompt(message);
//        ChatResponse res = chatModel.call(prompt);
//        System.out.println(res);
//        Flux.just(Objects.requireNonNull(res.getResult().getOutput().getText()))
        //流式方案
        Flux<String> stream = aiService.streamAI(message);
        return stream;
    }
}
